//
//  EFAFeedbackCRView.m
//  efairy
//
//  Created by XiangDongMBP on 2017/9/18.
//  Copyright © 2017年 East. All rights reserved.
//

#import "EFAFeedbackCRView.h"
#import "EFAModel.h"
#import "SZTextView.h"

@interface EFAFeedbackCRView ()<UITextViewDelegate>

@end

@implementation EFAFeedbackCRView

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.szTextView.delegate = self;
}

#pragma mark - UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView {
    NSString *toBeString = textView.text;
    NSInteger maxLength = 500;
    //获取高亮部分
    UITextRange *selectedRange = [textView markedTextRange];
    UITextPosition *position = [textView positionFromPosition:selectedRange.start offset:0];
    // 没有高亮选择的字，则对已输入的文字进行字数统计和限制
    if (!position || !selectedRange) {
        if (toBeString.length > maxLength) {
            NSRange rangeIndex = [toBeString rangeOfComposedCharacterSequenceAtIndex:maxLength];
            if (rangeIndex.length == 1) {
                textView.text = [toBeString substringToIndex:maxLength];
            } else {
                NSRange rangeRange = [toBeString rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, maxLength)];
                textView.text = [toBeString substringWithRange:rangeRange];
            }
        }
    }
    
    // 键盘不在联想状态才进行判断
    if (!selectedRange) {
        self.pubModel.efairyfeedback_content = textView.text;
    }
}

@end
